package singleton;

/**
 * @description:
 * @author: jhy
 * @time: 2021/4/22 21:57
 */
public class HungrySingletonSafeTest {

    public static void main(String[] args) {
        new Thread(()->{
            System.out.println(HungrySingletonSafe.getInstance());
        }).start();
        new Thread(()->{
            System.out.println(HungrySingletonSafe.getInstance());
        }).start();
    }
}


//饿汉式实现单例模式--->线程安全
class HungrySingletonSafe{

    private static HungrySingletonSafe instance = new HungrySingletonSafe();

    //私有化构造器
    private HungrySingletonSafe(){

    }
    //提供一个公共访问节点，已获得该实例
    public static HungrySingletonSafe getInstance(){
        return instance;
    }

}
